package com.rain.core.saver;

import com.rain.ai.model.MultiFileCodeResult;
import com.rain.exception.BusinessException;
import com.rain.exception.ErrorCode;
import com.rain.enums.CodeGenTypeEnum;
import org.apache.commons.lang3.StringUtils;

public class MultiCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult> {
    @Override
    protected void validFile(MultiFileCodeResult result) {
        super.validFile(result);
        if(StringUtils.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"htmlCode不能为空");
        }
    }

    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFiles(MultiFileCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());
        writeToFile(baseDirPath,"style.css",result.getCssCode());
        writeToFile(baseDirPath,"script.js",result.getJsCode());
    }
}
